<div class="container-fluid">
    <div class="row">
        <div class="col-lg-12">
            <div class="card">
                <div class="card-toolbar clearfix">
                    <form class="form-inline pull-right" role="form">
                        <div class="form-group m-b-5">
                            <input type="hidden" id="startDate"/>
                            <input type="hidden" id="endDate"/>
                            <input type="text" id="dates" class="form-control"/>
                        </div>
                        <a class="btn btn-success m-b-5" href="#!" id="search_v_btn"><i class="mdi mdi-magnify"></i> 搜索</a>
                    </form>
                    <div class="toolbar-btn-action">
                        <a class="btn btn-default m-r-5" href="javascript:goBack();"><i
                                class="mdi mdi-keyboard-backspace"></i>
                            返回</a>
                    </div>
                </div>
                <div class="card-body">
                    <div class="table-responsive">
                        <table class="table table-bordered" id="visit_table">
                        </table>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
<script type="text/javascript">
    var $visitTable = $('#visit_table');

    $(document).ready(function () {
        initDates();

        $('#search_v_btn').click(function () {
            $visitTable.bootstrapTable('refresh');
        })
    });

    function setDate(start, end) {
        $('#startDate').val(start.format('YYYY-MM-DD HH:mm:ss'));
        $('#endDate').val(end.format('YYYY-MM-DD HH:mm:ss'));
    }

    function goBack(){
        openPage('pages/home.html')
    }

    function initDates() {
        var s = moment().startOf('month');
        var e = moment().endOf('month');

        setDate(s, e);

        $('#dates').daterangepicker({
            startDate: s,
            endDate: e
        }, function (start, end, label) {
            setDate(start, end);
        });

        initVisitRecordTable();
    }

    function initVisitRecordTable() {
        $visitTable.bootstrapTable({
            url: base_url + visit_record_url,       // 请求地址
            showRefresh: false,                     // 刷新按钮
            toolbar: '#toolbar',
            pagination: true,                       // 分页
            sidePagination: 'server',               // 服务器端分页
            pageSize: 10,                           // 每页显示的记录数
            pageList: [10, 20, 50],                 // 可选择的每页记录数
            queryParams: function (params) {        // 请求参数
                var pageNo = params.offset == 0 ? 1 : params.offset == 0;
                return {
                    'shortId': 'YuQRc',
                    'startTime': $('#startDate').val(),
                    'endTime': $('#endDate').val(),
                    'pageNo': pageNo,
                    'pageSize': params.limit
                }
            },
            ajaxOptions: {
                headers: {                                          // 请求头
                    'xin-token': $.cookie(admin_token_key)
                }
            },
            onLoadSuccess: function () {
                $('[data-toggle="tooltip"]').tooltip();
            },
            onLoadError: function (status) {                        // 错误处理
                if (status == err_unauthorized) {
                    $.cookie(admin_token_key, '')
                    window.location.href = 'login.html'
                }
            },
            responseHandler: function (resp) {                      // 处理返回数据
                if (resp.code == success_code) {
                    return {
                        total: resp.data.totalCount,
                        rows: resp.data.records
                    }
                } else if (resp.code == err_unauthorized) {
                    $.cookie(admin_token_key, '')
                    window.location.href = 'login.html'
                } else {
                    lightyear.notify(resp.message, 'danger', 2000, 'mdi mdi-emoticon-sad', 'top', 'right');
                }
            },
            columns: [
                {
                    title: '序号',
                    field: 'id',
                    formatter: function (value, row, index) {
                        index++
                        return '<label class="lyear-checkbox checkbox-primary">' +
                            '<input type="checkbox" name="ids" value="' + value + '"><span>' + index++ + '</span>' +
                            '</label>'
                    }
                },
                {
                    title: '访问时间',
                    field: 'visitTime',
                    formatter:function (value,row,index) {
                        return moment(value).format('YYYY-MM-DD HH:mm:ss')
                    }
                },
                {
                    title: '访问Ip',
                    field: 'clientIp'
                },
                {
                    title: '国家',
                    field: 'countryCode'
                },
                {
                    title: '地区',
                    field: 'region'
                },
                {
                    title: '设备类型',
                    field: 'deviceType'
                },
                {
                    title: '操作系统',
                    field: 'os'
                },
                {
                    title: '浏览器',
                    field: 'browser'
                },
                {
                    title: '网络类型',
                    field: 'network'
                },
                {
                    title: '来源域名',
                    field: 'refererDomain'
                },
            ]
        })
    }

</script>